<template>
  <view class="coupon-card" :style="{ background: bgColor }">
    <!-- 左侧金额区域 -->
    <view class="card-left">
      <view class="pt_left">
        <view class="pt_left-content">
          <!-- 金额显示 -->
          <view class="f1" v-if="type === 'money'">
            <text class="t0">￥</text>
            <text class="t1">{{ amount }}</text>
          </view>
          <!-- 折扣显示 -->
          <view class="f1" v-if="type === 'discount'">
            <text class="t1">{{ discount }}</text>
            <text class="t0">折</text>
          </view>
          <!-- 次数显示 -->
          <view class="f1" v-if="type === 'times'">
            <text class="t1">{{ times }}</text>
            <text class="t2">次</text>
          </view>
          <!-- 使用条件 -->
          <view class="f2" v-if="minPrice > 0">
            满{{ minPrice }}元可用
          </view>
        </view>
      </view>
    </view>

    <!-- 右侧信息区域 -->
    <view class="card-right">
      <view class="card-title">{{ title }}</view>
      <view class="card-tags">
        <text class="tag" v-for="(tag, index) in tags" :key="index">{{ tag }}</text>
      </view>
      <view class="card-time">有效期至 {{ endTime }}</view>
      <view class="card-merchant" v-if="merchant">适用商家：{{ merchant }}</view>
    </view>

    <!-- 使用按钮 -->
    <view class="card-btn" :style="{ background: btnColor }" @tap="onUse">
      去使用
    </view>

    <!-- 已使用/已过期标记 -->
    <image v-if="status === 'used'" class="status-img" src="/static/img/ysy.png"></image>
    <image v-if="status === 'expired'" class="status-img" src="/static/img/ygq.png"></image>
  </view>
</template>

<script>
export default {
  name: 'coupon-card',
  props: {
    // 优惠券类型：money-金额券，discount-折扣券，times-次数券
    type: {
      type: String,
      default: 'money'
    },
    // 金额
    amount: {
      type: [Number, String],
      default: 0
    },
    // 折扣
    discount: {
      type: [Number, String],
      default: 0
    },
    // 次数
    times: {
      type: [Number, String],
      default: 0
    },
    // 最低使用金额
    minPrice: {
      type: [Number, String],
      default: 0
    },
    // 优惠券标题
    title: {
      type: String,
      default: ''
    },
    // 标签数组
    tags: {
      type: Array,
      default: () => []
    },
    // 结束时间
    endTime: {
      type: String,
      default: ''
    },
    // 适用商家
    merchant: {
      type: String,
      default: ''
    },
    // 背景颜色
    bgColor: {
      type: String,
      default: '#efe8fb'
    },
    // 按钮颜色
    btnColor: {
      type: String,
      default: '#07c160'
    },
    // 状态：used-已使用，expired-已过期
    status: {
      type: String,
      default: ''
    }
  },
  methods: {
    onUse() {
      this.$emit('use')
    }
  }
}
</script>

<style lang="scss" scoped>
.coupon-card {
  display: flex;
  align-items: center;
  width: 100%;
  border-radius: 8px;
  position: relative;
  margin-bottom: 20rpx;
  color: #fff;
  -webkit-mask-image: radial-gradient(circle at 88px 4px, transparent 4px, red 4.5px), radial-gradient(closest-side circle at 50%, red 99%, transparent 100%);
  -webkit-mask-repeat: repeat, repeat-y;
  -webkit-mask-position: 0 -8rpx, 168rpx;
}

.card-left {
  width: 88px;
  text-align: center;
  font-size: 18px;
}

.pt_left {
  background: transparent;
  min-height: 200rpx;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.pt_left-content {
  width: 100%;
  height: 100%;
  margin: 30rpx 0;
  border-right: 1px dashed #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.f1 {
  font-size: 40rpx;
  font-weight: bold;
  text-align: center;
}

.t0 {
  padding-right: 0;
}

.t1 {
  font-size: 60rpx;
}

.t2 {
  padding-left: 10rpx;
}

.f2 {
  font-size: 20rpx;
  text-align: center;
  margin-top: 10rpx;
}

.card-right {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 26rpx;
  font-weight: 700;
  margin-bottom: 10rpx;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 10rpx;
  
  .tag {
    font-size: 20rpx;
    padding: 4rpx 12rpx;
    border-radius: 4rpx;
    margin-right: 10rpx;
    margin-bottom: 6rpx;
    background: rgba(255, 255, 255, 0.2);
  }
}

.card-time {
  font-size: 24rpx;
  margin-bottom: 6rpx;
}

.card-merchant {
  font-size: 24rpx;
}

.card-btn {
  position: absolute;
  right: 30rpx;
  top: 50%;
  transform: translateY(-50%);
  padding: 10rpx 30rpx;
  border-radius: 30rpx;
  font-size: 24rpx;
  color: #fff;
}

.status-img {
  position: absolute;
  right: 30rpx;
  top: 50%;
  transform: translateY(-50%);
  width: 100rpx;
  height: 100rpx;
}
</style> 